package com.atguigu.yygh.hosp.controller.admin;

import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.result.R;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/*==========================================
      时 间:   2022-04-19
      讲 师:   刘  辉
      描 述:   尚硅谷教学团队
 ==========================================*/
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;


    //修改医院状态

    @PutMapping("/{id}/{status}")
    public R updateStatus(@PathVariable String id,@PathVariable Integer status){
        hospitalService.updateStatus(id,status);
        return R.ok();
    }

    @GetMapping("/{page}/{limit}")
    public R getHospitalPage(@PathVariable Integer page, @PathVariable Integer limit,HospitalQueryVo hospitalQueryVo){
        Page<Hospital> page1= hospitalService.getHospitalPage(page,limit,hospitalQueryVo);

        return R.ok().data("total",page1.getTotalElements()).data("rows",page1.getContent());
    }


    @GetMapping("/detail/{id}")
    public R detail(@PathVariable String id){
        Hospital hospital= hospitalService.detail(id);
        return R.ok().data("hospital",hospital);
    }
}
